﻿using Apps.Common;
using Apps.Models;
using System.Linq;
using System.Collections.Generic;
using Apps.Models.PUB;
using Apps.IBLL.PUB;
using Microsoft.Practices.Unity;
using System;

namespace Apps.BLL.PUB
{
    public partial class V_LOG_LMSEXCHANGEBLL
    {
        public DBContainer db = new DBContainer();

        public List<V_LOG_LMSEXCHANGEModel> GetList(ref GridPager pager, string testcode, string startdate, string enddate)
        {
            IQueryable<V_LOG_LMSEXCHANGE> queryData = this.db.V_LOG_LMSEXCHANGE.AsQueryable<V_LOG_LMSEXCHANGE>();
            if (!string.IsNullOrEmpty(testcode))
            {
                queryData = queryData.Where(m => m.BATCH_CODE_A.Contains(testcode) || m.BATCH_CODE_B.Contains(testcode));
            }
            if (!string.IsNullOrEmpty(startdate))
            {
                DateTime dStartDate = DateTime.ParseExact(startdate, "yyyy-MM-dd", null);
                queryData = queryData.Where(m => m.OPERATE_TIME >= dStartDate);
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                DateTime dEndDate = DateTime.ParseExact(enddate, "yyyy-MM-dd", null).AddDays(1);
                queryData = queryData.Where(m => m.OPERATE_TIME < dEndDate);
            }

            var data = from m1 in queryData
                       join m3 in db.SysUser on m1.LOG_ID equals m3.Id into l3
                       from l33 in l3.DefaultIfEmpty()
                       join m4 in db.SysUser on m1.LOG_ID equals m4.Id into l4
                       from l44 in l4.DefaultIfEmpty()
                       select new V_LOG_LMSEXCHANGEModel()
                       {
                           LOG_ID = m1.LOG_ID,
                           BATCH_CODE_A = m1.BATCH_CODE_A,
                           BATCH_CODE_B = m1.BATCH_CODE_B,
                           OPERATE_CONTENT = m1.OPERATE_CONTENT,
                           OPERATE_USER_ID = m1.OPERATE_USER_ID,
                           TRUENAME = m1.TRUENAME,
                           OPERATE_TIME = m1.OPERATE_TIME,
                           URL = m1.URL,
                           FILE_NAME=m1.FILE_NAME
                       };


            pager.totalRows = data.Count();
            //排序
            data = LinqHelper.SortingAndPaging(data, pager.sort, pager.order, pager.page, pager.rows);
            var retval = data.ToList();
            return retval;
        }
    }
}
